import Vue from 'vue'
import { MessageBox } from 'mint-ui';
import router from '@/store/router'
export default {
    getrepairState (context) {
        Vue.prototype.$newHttp.post('/cmItem/maintain/list', {})
            .then(res => {
                context.commit('setRepairListState',res.data);
            })
            .catch(err => {console.log(err)});
    },
    repairMessage (context,params) {
        Vue.prototype.$newHttp.post('/cmItem/maintain/make', params)
            .then(res => {
                context.commit('setSelectData',res.data);
            }
        ).catch(err => {console.log(err)});
    },
    repairOrderSubmit(context,params){
        Vue.prototype.$newHttp.post('/order/makeCmOrder', params)
            .then(res => {
                if (res.status === 0) {
                    MessageBox.alert(res.message).then(()=>{
                        router.push({path:'/repair'});
                    });
                } else if (res.status === 1) {
                    MessageBox.alert('预约成功').then(()=>{
                        context.commit('setOrderNumber',res.data.orderNumber);
                        router.push({path:'/repairSuccess',query:{orderNumber:res.data.orderNumber}});
                    });
                }
            }
        ).catch(err => {console.log(err)});
    },
    repairOrderData(context,params){
        Vue.prototype.$newHttp.post('/order/detail', params)
            .then(res => {
                if (res.status === 0) {
                    MessageBox.alert(res.message);
                } else if (res.status === 1) {
                    console.log(res.data)
                    context.commit('setOrderDetail',res.data);
                }
            }
        ).catch(err => {console.log(err)});
    }
}